
****************************************************************************************************
****************************************************************************************************
*Replication file for:
*The Importance of a Liberal Power's Attention to Democratic Elections Around the World
*Johannes Bubeck Ashrakat Elshehawy Nikolay Marinov Federico Nanni
****************************************************************************************************
****************************************************************************************************


*---
* This do file takes the sanctions data that we have in a doc-by-doc format and counts the number of times trigger words appear in these documents


set more off
drop _all
macro drop _all

*please change working directory
cd "/Data"
import delimited using doc-by-doc.csv
capture drop v15*

gen hrdoc=0

label var hrdoc "number of times doc classified as HR"

gen heatmap=0

label var heatmap "number of times doc classified by heatmap categories"


foreach i of varlist sanct-for_assist	{		

	replace `i'=trim(`i')

}



*---

*	Categories for Y-triggers 

*	election
*	democracy
*	illiberal
*	governance
*	transition
*	coup
*	reform
*	opposition
*	humrights
*	repression
*	violence
*	

*---
*	Categories and trigger combinations (some triggers belong in >1 category)	
*
*	humrights
*	min_wom adv_hr abuse dem_fre_act elim_slave elim_aparth univ_right un_dec_hr supp_freed resp_right res_hr_abuse rel_freedom pol_prison equ_opp forc_labour fr_dem_soc frd_inv_init free_speech freedom_act funda_freed honest_elect imp_trans hum_dig hum_prison hum_suffer human_right 
*	
*	coup
*	oust coup_risk coup dsrptlegpwr rest_consgvt 
*	
*	democracy
*	dem_resist dem_process dem_outcome dem_goal dem_act comt_democz dem_elect dem_inst dem_path dem_prom dem_sol_act help_dem elect_gov democratic dem_value dem_solidar democracy democratizt grow_civ_soc pro_democ meet_int_std lack_legitld mlparty_dem toward_democ demelc_gov dem_govt dem_govnce dem_fre_act freedom_act dem_trans dem_evo fr_dem_soc rest_dem rest_demproc 
*	
*	governance
*	demelc_gov dem_govt dem_govnce rule_law good_govnce const_neg exploit_rule 
*	
*	transition
*	dem_trans dem_evo rest_dem rest_demproc trans supp_trans subtocivrule ref_med_polc normlz_gov enc_negot dem_change imp_trans open_pol_arn relinq_power sup_trans_gv rest_dem rest_demproc sup_ed_trans sup_ec_trans 
*	
*	reform
*	sup_ed_trans sup_ec_trans und_ref_pro polec_reform pol_reform supp_reform 
*	
*	election
*	frfa_pa_elec fraud elect_freed elect dem_fr_elect elect_fraud elect_res frfa_elec frfa_pp_elec rigg_elect prom_elect honest_elect frfa_ps_elec mlparty_elec ref_acce_res undem_elect unf_elect 
*	
*	illiberal
*	exploit_rule postp_elect obstr_democ dict assault_dem mil polsocecodet unconaccessi und_dem_pro 
*	
*	opposition
*	resp_opp opp_demand dem_opp withd_ch_opp rep_dem_opp int_opp disap_opp viol_opp 
*	
*	repression
*	withd_ch_opp rep_dem_opp int_opp crackd_opp pol_opp oppress gov_harass arrest aggress enddetpolopp initimidate persecute repress supp_freed 
*	
*	violence
*	viol_opp ren_viol gov_viol elect_viol prev_viol violence 
*	
*---
*	
*	ALL Y triggers
*	
*	elect elect_res rigg_elect unf_elect frfa_elec elect_viol elect_fraud mlparty_elec frfa_pa_elec frfa_ps_elec frfa_pp_elec lack_legitld human_right democratizt democracy dem_act dem_fre_act dem_sol_act democratic dem_trans dem_prom dem_govnce und_dem_pro dem_change demelc_gov rest_demproc rest_dem good_govnce abuse arrest repress rep_dem_opp withd_ch_opp disap_opp dict mil und_ref_pro crackd_opp viol_opp dem_opp resp_opp prev_viol pol_opp oppress unconaccessi subtocivrule fr_dem_soc coup_risk coup sup_ec_trans sup_trans_gv sup_ed_trans enddetpolopp forc_labour pol_prison hum_prison res_hr_abuse adv_hr violence ren_viol initimidate meet_int_std enc_negot terrorism elim_slave rel_freedom fraud rule_law funda_freed gov_harass grow_civ_soc ref_med_polc prom_elect undem_elect dem_fr_elect mlparty_dem dem_elect elect_gov ref_acce_res honest_elect freedom_act toward_democ pro_democ pol_reform polec_reform help_dem supp_freed obstr_democ dem_evo assault_dem dem_inst dem_goal imp_trans dem_process trans supp_trans dem_outcome dem_resist aggress hum_dig frd_inv_init equ_opp un_dec_hr univ_right resp_right free_speech gov_viol int_opp oust polsocecodet rest_consgvt dem_solidar hum_suffer postp_elect elect_freed opp_demand comt_democz dsrptlegpwr persecute dem_path relinq_power normlz_gov supp_reform const_neg open_pol_arn exploit_rule elim_aparth dem_value dem_govt min_wom
*----	

*---
*	
*	
*	Categories for X-triggers 
*	
*	milaid
*	econaid
*	trade
*	finance
*	assets
*	smart
*	arms
*	
*---

*---
*	Categories and trigger combinations (some triggers belong in >1 category)	
*
*	arms
*	prhb_arm_tr mod_mil_rel 
*	
*	assets
*	frz_fin_res asset_frz blck_prop_gv blck_gv blck_account blck_asset block_prop 
*	
*	econaid
*	prhb_ecsupas prhb_hr_aid lim_fund withh_loan termn_assist rst_ness_ass cut_econ_bnf prhb_av_fund assist_cond reduc_assist no_ass_prov bar_fund bar_assist prhb_usefund block_fund gvgv_econmil furn_assist prhb_funds susp_assist cond_assist prhb_assist prhb_prv_ass limit_assist withh_assist prhb_rec_ass prhb_for_ass gov_assist rest_assist rev_assist cut_aid redu_aid restrict_aid susp_aid withh_aid withh_fund rest_for_ass rev_for_ass for_assist no_fundsexpn 
*	
*	milaid
*	prhb_mil_ass susp_mil_trn rest_mil_ass prhb_fr_mil termn_milass termn_assist rst_ness_ass prhb_av_fund assist_cond reduc_assist no_ass_prov bar_fund bar_assist prhb_usefund block_fund gvgv_econmil furn_assist prhb_funds susp_assist cond_assist prhb_assist prhb_prv_ass limit_assist withh_assist prhb_rec_ass prhb_for_ass gov_assist rest_assist rev_assist cut_aid redu_aid restrict_aid susp_aid withh_aid withh_fund rest_for_ass rev_for_ass for_assist mod_mil_rel no_fundsexpn 
*	
*	finance
*	trv_fin_sanc fin_trv_sanc cash_assist fin_sanc frz_fund block_loan prhb_transc prhb_payment unlic_fintra inv_sanc prhb_inv opp_loan lim_abl_fex prhb_finan 
*	
*	smart
*	rest_int_trv susp_visa den_off_entr den_lics trv_sanct visa_ban susp_air_trn den_ent trv_ban deny_visa rest_trv trv_fin_sanc prhb_visa susp_entry prhb_entr fin_trv_sanc 
*	
*	trade
*	exp_sanct rest_exp prhb_exp mod_econ_rel end_econ_ag end_trade_ag withh_trade prhb_imp rest_imp expimpbank trade_war ban_imp prhb_sale prhb_exim_bk boycott prhb_trade prhb_salesup sell_product cut_econ_bnf sanct_trade ecn_isol ecn_pol_isol 
*	
*---
*	
*	ALL X
*	
*	sanct sanct_act emb block ban prhb_funds dec penalty restraint visa_ban trv_sanct trv_fin_sanc fin_trv_sanc cash_assist susp_assist cond_assist prhb_assist prhb_prv_ass limit_assist withh_assist prhb_rec_ass prhb_mil_ass prhb_for_ass gov_assist rest_assist rev_assist rev_bil_arng prhb_arm_tr cut_aid redu_aid restrict_aid susp_aid withh_aid end_trade_ag end_econ_ag withh_trade mod_rel mod_bi_rel mod_econ_rel mod_mil_rel mod_pol_rel cut_econ_bnf withh_fund susp_mil_trn susp_air_trn prhb_ext_ben frz_prop frz_fin_res fin_sanc frz_fund den_lics gvgv_contr prhb_imp prhb_exp rest_imp rest_exp expimpbank exp_sanct termn_assist stoppage den_ent den_off_entr trv_ban asset_frz trade_war susp_elg_ben elg_ben rst_ness_ass susp_coop_ag prhb_av_fund assist_cond reduc_assist no_ass_prov bar_fund bar_assist prhb_ecsupas susp_visa prhb_usefund prhb_hr_aid block_loan block_fund gvgv_econmil condemn reex_pol expr_sen pressure vote_ag expr_cong boycott prhb_transc prhb_exim_bk econ_meas prhb_trade deny_visa rest_int_trv rest_trv prhb_entr susp_entry prohb prhb_sale prhb_salesup prhb_contrib sanct_trade prhb_payment ban_imp certain_rest blck_prop_gv blck_gv blck_account unlic_fintra blck_asset block_prop inv_sanc prhb_inv opp_loan isolat ecn_isol ecn_pol_isol lim_abl_fex lim_abilty inc_prss inc_int_prss stif_voice urge_intcomm stand_up_for US_foster take_meas comm_prog speakout_dem exp_concern sell_product prhb_visa rest_mil_ass lim_fund prhb_fr_mil withh_loan prhb_finan furn_assist termn_milass no_fundsexpn rest_for_ass rev_for_ass for_assist
*	
*---


*--->
*	Task 1: All mentions of keywords 

log using quiet_noise.log, text replace

quietly{

local sanct=0
local sanct_act=0
local emb=0
local block=0
local ban=0
local prhb_funds=0
local dec=0
local penalty=0
local restraint=0
local visa_ban=0
local trv_sanct=0
local trv_fin_sanc=0
local fin_trv_sanc=0
local cash_assist=0
local susp_assist=0
local cond_assist=0
local prhb_assist=0
local prhb_prv_ass=0
local limit_assist=0
local withh_assist=0
local prhb_rec_ass=0
local prhb_mil_ass=0
local prhb_for_ass=0
local gov_assist=0
local rest_assist=0
local rev_assist=0
local rev_bil_arng=0
local prhb_arm_tr=0
local cut_aid=0
local redu_aid=0
local restrict_aid=0
local susp_aid=0
local withh_aid=0
local end_trade_ag=0
local end_econ_ag=0
local withh_trade=0
local mod_rel=0
local mod_bi_rel=0
local mod_econ_rel=0
local mod_mil_rel=0
local mod_pol_rel=0
local cut_econ_bnf=0
local withh_fund=0
local susp_mil_trn=0
local susp_air_trn=0
local prhb_ext_ben=0
local frz_prop=0
local frz_fin_res=0
local fin_sanc=0
local frz_fund=0
local den_lics=0
local gvgv_contr=0
local prhb_imp=0
local prhb_exp=0
local rest_imp=0
local rest_exp=0
local expimpbank=0
local exp_sanct=0
local termn_assist=0
local stoppage=0
local den_ent=0
local den_off_entr=0
local trv_ban=0
local asset_frz=0
local trade_war=0
local susp_elg_ben=0
local elg_ben=0
local rst_ness_ass=0
local susp_coop_ag=0
local prhb_av_fund=0
local assist_cond=0
local reduc_assist=0
local no_ass_prov=0
local bar_fund=0
local bar_assist=0
local prhb_ecsupas=0
local susp_visa=0
local prhb_usefund=0
local prhb_hr_aid=0
local block_loan=0
local block_fund=0
local gvgv_econmil=0
local condemn=0
local reex_pol=0
local expr_sen=0
local pressure=0
local vote_ag=0
local expr_cong=0
local boycott=0
local prhb_transc=0
local prhb_exim_bk=0
local econ_meas=0
local prhb_trade=0
local deny_visa=0
local rest_int_trv=0
local rest_trv=0
local prhb_entr=0
local susp_entry=0
local prohb=0
local prhb_sale=0
local prhb_salesup=0
local prhb_contrib=0
local sanct_trade=0
local prhb_payment=0
local ban_imp=0
local certain_rest=0
local blck_prop_gv=0
local blck_gv=0
local blck_account=0
local unlic_fintra=0
local blck_asset=0
local block_prop=0
local inv_sanc=0
local prhb_inv=0
local opp_loan=0
local isolat=0
local ecn_isol=0
local ecn_pol_isol=0
local lim_abl_fex=0
local lim_abilty=0
local inc_prss=0
local inc_int_prss=0
local stif_voice=0
local urge_intcomm=0
local stand_up_for=0
local US_foster=0
local take_meas=0
local comm_prog=0
local speakout_dem=0
local exp_concern=0
local sell_product=0
local prhb_visa=0
local rest_mil_ass=0
local lim_fund=0
local prhb_fr_mil=0
local withh_loan=0
local prhb_finan=0
local furn_assist=0
local termn_milass=0
local no_fundsexpn=0
local rest_for_ass=0
local rev_for_ass=0
local for_assist=0
local elect=0
local elect_res=0
local rigg_elect=0
local unf_elect=0
local frfa_elec=0
local elect_viol=0
local elect_fraud=0
local mlparty_elec=0
local frfa_pa_elec=0
local frfa_ps_elec=0
local frfa_pp_elec=0
local lack_legitld=0
local human_right=0
local democratizt=0
local democracy=0
local dem_act=0
local dem_fre_act=0
local dem_sol_act=0
local democratic=0
local dem_trans=0
local dem_prom=0
local dem_govnce=0
local und_dem_pro=0
local dem_change=0
local demelc_gov=0
local rest_demproc=0
local rest_dem=0
local good_govnce=0
local abuse=0
local arrest=0
local repress=0
local rep_dem_opp=0
local withd_ch_opp=0
local disap_opp=0
local dict=0
local mil=0
local und_ref_pro=0
local crackd_opp=0
local viol_opp=0
local dem_opp=0
local resp_opp=0
local prev_viol=0
local pol_opp=0
local oppress=0
local unconaccessi=0
local subtocivrule=0
local fr_dem_soc=0
local coup_risk=0
local coup=0
local sup_ec_trans=0
local sup_trans_gv=0
local sup_ed_trans=0
local enddetpolopp=0
local forc_labour=0
local pol_prison=0
local hum_prison=0
local res_hr_abuse=0
local adv_hr=0
local violence=0
local ren_viol=0
local intimidate=0
local meet_int_std=0
local enc_negot=0
local terrorism=0
local elim_slave=0
local rel_freedom=0
local fraud=0
local rule_law=0
local funda_freed=0
local gov_harass=0
local grow_civ_soc=0
local ref_med_polc=0
local prom_elect=0
local undem_elect=0
local dem_fr_elect=0
local mlparty_dem=0
local dem_elect=0
local elect_gov=0
local ref_acce_res=0
local honest_elect=0
local freedom_act=0
local toward_democ=0
local pro_democ=0
local pol_reform=0
local polec_reform=0
local help_dem=0
local supp_freed=0
local obstr_democ=0
local dem_evo=0
local assault_dem=0
local dem_inst=0
local dem_goal=0
local imp_trans=0
local dem_process=0
local trans=0
local supp_trans=0
local dem_outcome=0
local dem_resist=0
local aggress=0
local hum_dig=0
local frd_inv_init=0
local equ_opp=0
local un_dec_hr=0
local univ_right=0
local resp_right=0
local free_speech=0
local gov_viol=0
local int_opp=0
local oust=0
local polsocecodet=0
local rest_consgvt=0
local dem_solidar=0
local hum_suffer=0
local postp_elect=0
local elect_freed=0
local opp_demand=0
local comt_democz=0
local dsrptlegpwr=0
local persecute=0
local dem_path=0
local relinq_power=0
local normlz_gov=0
local supp_reform=0
local const_neg=0
local open_pol_arn=0
local exploit_rule=0
local elim_aparth=0
local dem_value=0
local dem_govt=0
local min_wom=0

local num=_N

forvalues n=1/`num' { 

	foreach l of varlist sanct-for_assist {

	local wc=wordcount(`l'[`n'])
		
		forvalues j = 1(1)`wc'	{

			di substr(word(`l'[`n'],`j'),1,strpos(word(`l'[`n'],`j'),":")-1)
			di real(substr(word(`l'[`n'],`j'),-(strlen(word(`l'[`n'],`j'))-strpos(word(`l'[`n'],`j'),":")),strlen(word(`l'[`n'],`j'))-strpos(word(`l'[`n'],`j'),":")))
			local i=substr(word(`l'[`n'],`j'),1,strpos(word(`l'[`n'],`j'),":")-1)
			local k=real(substr(word(`l'[`n'],`j'),-(strlen(word(`l'[`n'],`j'))-strpos(word(`l'[`n'],`j'),":")),strlen(word(`l'[`n'],`j'))-strpos(word(`l'[`n'],`j'),":")))
			local `i'=``i''+`k'
			local `l'=``l''+`k'

		}

	}

}

noisily:di "sanct",`sanct' 
noisily:di "sanct_act",`sanct_act' 
noisily:di "emb",`emb' 
noisily:di "block",`block' 
noisily:di "ban",`ban' 
noisily:di "prhb_funds",`prhb_funds' 
noisily:di "dec",`dec' 
noisily:di "penalty",`penalty' 
noisily:di "restraint",`restraint' 
noisily:di "visa_ban",`visa_ban' 
noisily:di "trv_sanct",`trv_sanct' 
noisily:di "trv_fin_sanc",`trv_fin_sanc' 
noisily:di "fin_trv_sanc",`fin_trv_sanc' 
noisily:di "cash_assist",`cash_assist' 
noisily:di "susp_assist",`susp_assist' 
noisily:di "cond_assist",`cond_assist' 
noisily:di "prhb_assist",`prhb_assist' 
noisily:di "prhb_prv_ass",`prhb_prv_ass' 
noisily:di "limit_assist",`limit_assist' 
noisily:di "withh_assist",`withh_assist' 
noisily:di "prhb_rec_ass",`prhb_rec_ass' 
noisily:di "prhb_mil_ass",`prhb_mil_ass' 
noisily:di "prhb_for_ass",`prhb_for_ass' 
noisily:di "gov_assist",`gov_assist' 
noisily:di "rest_assist",`rest_assist' 
noisily:di "rev_assist",`rev_assist' 
noisily:di "rev_bil_arng",`rev_bil_arng' 
noisily:di "prhb_arm_tr",`prhb_arm_tr' 
noisily:di "cut_aid",`cut_aid' 
noisily:di "redu_aid",`redu_aid' 
noisily:di "restrict_aid",`restrict_aid' 
noisily:di "susp_aid",`susp_aid' 
noisily:di "withh_aid",`withh_aid' 
noisily:di "end_trade_ag",`end_trade_ag' 
noisily:di "end_econ_ag",`end_econ_ag' 
noisily:di "withh_trade",`withh_trade' 
noisily:di "mod_rel",`mod_rel' 
noisily:di "mod_bi_rel",`mod_bi_rel' 
noisily:di "mod_econ_rel",`mod_econ_rel' 
noisily:di "mod_mil_rel",`mod_mil_rel' 
noisily:di "mod_pol_rel",`mod_pol_rel' 
noisily:di "cut_econ_bnf",`cut_econ_bnf' 
noisily:di "withh_fund",`withh_fund' 
noisily:di "susp_mil_trn",`susp_mil_trn' 
noisily:di "susp_air_trn",`susp_air_trn' 
noisily:di "prhb_ext_ben",`prhb_ext_ben' 
noisily:di "frz_prop",`frz_prop' 
noisily:di "frz_fin_res",`frz_fin_res' 
noisily:di "fin_sanc",`fin_sanc' 
noisily:di "frz_fund",`frz_fund' 
noisily:di "den_lics",`den_lics' 
noisily:di "gvgv_contr",`gvgv_contr' 
noisily:di "prhb_imp",`prhb_imp' 
noisily:di "prhb_exp",`prhb_exp' 
noisily:di "rest_imp",`rest_imp' 
noisily:di "rest_exp",`rest_exp' 
noisily:di "expimpbank",`expimpbank' 
noisily:di "exp_sanct",`exp_sanct' 
noisily:di "termn_assist",`termn_assist' 
noisily:di "stoppage",`stoppage' 
noisily:di "den_ent",`den_ent' 
noisily:di "den_off_entr",`den_off_entr' 
noisily:di "trv_ban",`trv_ban' 
noisily:di "asset_frz",`asset_frz' 
noisily:di "trade_war",`trade_war' 
noisily:di "susp_elg_ben",`susp_elg_ben' 
noisily:di "elg_ben",`elg_ben' 
noisily:di "rst_ness_ass",`rst_ness_ass' 
noisily:di "susp_coop_ag",`susp_coop_ag' 
noisily:di "prhb_av_fund",`prhb_av_fund' 
noisily:di "assist_cond",`assist_cond' 
noisily:di "reduc_assist",`reduc_assist' 
noisily:di "no_ass_prov",`no_ass_prov' 
noisily:di "bar_fund",`bar_fund' 
noisily:di "bar_assist",`bar_assist' 
noisily:di "prhb_ecsupas",`prhb_ecsupas' 
noisily:di "susp_visa",`susp_visa' 
noisily:di "prhb_usefund",`prhb_usefund' 
noisily:di "prhb_hr_aid",`prhb_hr_aid' 
noisily:di "block_loan",`block_loan' 
noisily:di "block_fund",`block_fund' 
noisily:di "gvgv_econmil",`gvgv_econmil' 
noisily:di "condemn",`condemn' 
noisily:di "reex_pol",`reex_pol' 
noisily:di "expr_sen",`expr_sen' 
noisily:di "pressure",`pressure' 
noisily:di "vote_ag",`vote_ag' 
noisily:di "expr_cong",`expr_cong' 
noisily:di "boycott",`boycott' 
noisily:di "prhb_transc",`prhb_transc' 
noisily:di "prhb_exim_bk",`prhb_exim_bk' 
noisily:di "econ_meas",`econ_meas' 
noisily:di "prhb_trade",`prhb_trade' 
noisily:di "deny_visa",`deny_visa' 
noisily:di "rest_int_trv",`rest_int_trv' 
noisily:di "rest_trv",`rest_trv' 
noisily:di "prhb_entr",`prhb_entr' 
noisily:di "susp_entry",`susp_entry' 
noisily:di "prohb",`prohb' 
noisily:di "prhb_sale",`prhb_sale' 
noisily:di "prhb_salesup",`prhb_salesup' 
noisily:di "prhb_contrib",`prhb_contrib' 
noisily:di "sanct_trade",`sanct_trade' 
noisily:di "prhb_payment",`prhb_payment' 
noisily:di "ban_imp",`ban_imp' 
noisily:di "certain_rest",`certain_rest' 
noisily:di "blck_prop_gv",`blck_prop_gv' 
noisily:di "blck_gv",`blck_gv' 
noisily:di "blck_account",`blck_account' 
noisily:di "unlic_fintra",`unlic_fintra' 
noisily:di "blck_asset",`blck_asset' 
noisily:di "block_prop",`block_prop' 
noisily:di "inv_sanc",`inv_sanc' 
noisily:di "prhb_inv",`prhb_inv' 
noisily:di "opp_loan",`opp_loan' 
noisily:di "isolat",`isolat' 
noisily:di "ecn_isol",`ecn_isol' 
noisily:di "ecn_pol_isol",`ecn_pol_isol' 
noisily:di "lim_abl_fex",`lim_abl_fex' 
noisily:di "lim_abilty",`lim_abilty' 
noisily:di "inc_prss",`inc_prss' 
noisily:di "inc_int_prss",`inc_int_prss' 
noisily:di "stif_voice",`stif_voice' 
noisily:di "urge_intcomm",`urge_intcomm' 
noisily:di "stand_up_for",`stand_up_for' 
noisily:di "US_foster",`US_foster' 
noisily:di "take_meas",`take_meas' 
noisily:di "comm_prog",`comm_prog' 
noisily:di "speakout_dem",`speakout_dem' 
noisily:di "exp_concern",`exp_concern' 
noisily:di "sell_product",`sell_product' 
noisily:di "prhb_visa",`prhb_visa' 
noisily:di "rest_mil_ass",`rest_mil_ass' 
noisily:di "lim_fund",`lim_fund' 
noisily:di "prhb_fr_mil",`prhb_fr_mil' 
noisily:di "withh_loan",`withh_loan' 
noisily:di "prhb_finan",`prhb_finan' 
noisily:di "furn_assist",`furn_assist' 
noisily:di "termn_milass",`termn_milass' 
noisily:di "no_fundsexpn",`no_fundsexpn' 
noisily:di "rest_for_ass",`rest_for_ass' 
noisily:di "rev_for_ass",`rev_for_ass' 
noisily:di "for_assist",`for_assist' 
noisily:di "elect",`elect' 
noisily:di "elect_res",`elect_res' 
noisily:di "rigg_elect",`rigg_elect' 
noisily:di "unf_elect",`unf_elect' 
noisily:di "frfa_elec",`frfa_elec' 
noisily:di "elect_viol",`elect_viol' 
noisily:di "elect_fraud",`elect_fraud' 
noisily:di "mlparty_elec",`mlparty_elec' 
noisily:di "frfa_pa_elec",`frfa_pa_elec' 
noisily:di "frfa_ps_elec",`frfa_ps_elec' 
noisily:di "frfa_pp_elec",`frfa_pp_elec' 
noisily:di "lack_legitld",`lack_legitld' 
noisily:di "human_right",`human_right' 
noisily:di "democratizt",`democratizt' 
noisily:di "democracy",`democracy' 
noisily:di "dem_act",`dem_act' 
noisily:di "dem_fre_act",`dem_fre_act' 
noisily:di "dem_sol_act",`dem_sol_act' 
noisily:di "democratic",`democratic' 
noisily:di "dem_trans",`dem_trans' 
noisily:di "dem_prom",`dem_prom' 
noisily:di "dem_govnce",`dem_govnce' 
noisily:di "und_dem_pro",`und_dem_pro' 
noisily:di "dem_change",`dem_change' 
noisily:di "demelc_gov",`demelc_gov' 
noisily:di "rest_demproc",`rest_demproc' 
noisily:di "rest_dem",`rest_dem' 
noisily:di "good_govnce",`good_govnce' 
noisily:di "abuse",`abuse' 
noisily:di "arrest",`arrest' 
noisily:di "repress",`repress' 
noisily:di "rep_dem_opp",`rep_dem_opp' 
noisily:di "withd_ch_opp",`withd_ch_opp' 
noisily:di "disap_opp",`disap_opp' 
noisily:di "dict",`dict' 
noisily:di "mil",`mil' 
noisily:di "und_ref_pro",`und_ref_pro' 
noisily:di "crackd_opp",`crackd_opp' 
noisily:di "viol_opp",`viol_opp' 
noisily:di "dem_opp",`dem_opp' 
noisily:di "resp_opp",`resp_opp' 
noisily:di "prev_viol",`prev_viol' 
noisily:di "pol_opp",`pol_opp' 
noisily:di "oppress",`oppress' 
noisily:di "unconaccessi",`unconaccessi' 
noisily:di "subtocivrule",`subtocivrule' 
noisily:di "fr_dem_soc",`fr_dem_soc' 
noisily:di "coup_risk",`coup_risk' 
noisily:di "coup",`coup' 
noisily:di "sup_ec_trans",`sup_ec_trans' 
noisily:di "sup_trans_gv",`sup_trans_gv' 
noisily:di "sup_ed_trans",`sup_ed_trans' 
noisily:di "enddetpolopp",`enddetpolopp' 
noisily:di "forc_labour",`forc_labour' 
noisily:di "pol_prison",`pol_prison' 
noisily:di "hum_prison",`hum_prison' 
noisily:di "res_hr_abuse",`res_hr_abuse' 
noisily:di "adv_hr",`adv_hr' 
noisily:di "violence",`violence' 
noisily:di "ren_viol",`ren_viol' 
noisily:di "intimidate",`intimidate' 
noisily:di "meet_int_std",`meet_int_std' 
noisily:di "enc_negot",`enc_negot' 
noisily:di "terrorism",`terrorism' 
noisily:di "elim_slave",`elim_slave' 
noisily:di "rel_freedom",`rel_freedom' 
noisily:di "fraud",`fraud' 
noisily:di "rule_law",`rule_law' 
noisily:di "funda_freed",`funda_freed' 
noisily:di "gov_harass",`gov_harass' 
noisily:di "grow_civ_soc",`grow_civ_soc' 
noisily:di "ref_med_polc",`ref_med_polc' 
noisily:di "prom_elect",`prom_elect' 
noisily:di "undem_elect",`undem_elect' 
noisily:di "dem_fr_elect",`dem_fr_elect' 
noisily:di "mlparty_dem",`mlparty_dem' 
noisily:di "dem_elect",`dem_elect' 
noisily:di "elect_gov",`elect_gov' 
noisily:di "ref_acce_res",`ref_acce_res' 
noisily:di "honest_elect",`honest_elect' 
noisily:di "freedom_act",`freedom_act' 
noisily:di "toward_democ",`toward_democ' 
noisily:di "pro_democ",`pro_democ' 
noisily:di "pol_reform",`pol_reform' 
noisily:di "polec_reform",`polec_reform' 
noisily:di "help_dem",`help_dem' 
noisily:di "supp_freed",`supp_freed' 
noisily:di "obstr_democ",`obstr_democ' 
noisily:di "dem_evo",`dem_evo' 
noisily:di "assault_dem",`assault_dem' 
noisily:di "dem_inst",`dem_inst' 
noisily:di "dem_goal",`dem_goal' 
noisily:di "imp_trans",`imp_trans' 
noisily:di "dem_process",`dem_process' 
noisily:di "trans",`trans' 
noisily:di "supp_trans",`trans'
noisily:di "dem_outcome",`dem_outcome' 
noisily:di "dem_resist",`dem_resist' 
noisily:di "aggress",`aggress' 
noisily:di "hum_dig",`hum_dig' 
noisily:di "frd_inv_init",`frd_inv_init' 
noisily:di "equ_opp",`equ_opp' 
noisily:di "un_dec_hr",`un_dec_hr' 
noisily:di "univ_right",`univ_right' 
noisily:di "resp_right",`resp_right' 
noisily:di "free_speech",`free_speech' 
noisily:di "gov_viol",`gov_viol' 
noisily:di "int_opp",`int_opp' 
noisily:di "oust",`oust' 
noisily:di "polsocecodet",`polsocecodet' 
noisily:di "rest_consgvt",`rest_consgvt' 
noisily:di "dem_solidar",`dem_solidar' 
noisily:di "hum_suffer",`hum_suffer' 
noisily:di "postp_elect",`postp_elect' 
noisily:di "elect_freed",`elect_freed' 
noisily:di "opp_demand",`opp_demand' 
noisily:di "comt_democz",`comt_democz' 
noisily:di "dsrptlegpwr",`dsrptlegpwr' 
noisily:di "persecute",`persecute' 
noisily:di "dem_path",`dem_path' 
noisily:di "relinq_power",`relinq_power' 
noisily:di "normlz_gov",`normlz_gov' 
noisily:di "supp_reform",`supp_reform' 
noisily:di "const_neg",`const_neg' 
noisily:di "open_pol_arn",`open_pol_arn' 
noisily:di "exploit_rule",`exploit_rule' 
noisily:di "elim_aparth",`elim_aparth' 
noisily:di "dem_value",`dem_value' 
noisily:di "dem_govt",`dem_govt' 
noisily:di "min_wom",`min_wom' 

	
	
}


log close

*------>
*	Task 2: HR variable	
*	Here, the human rights doc variable is generated, for such discussion and sanctions


quietly{

local humrights="min_wom adv_hr abuse dem_fre_act elim_slave elim_aparth univ_right un_dec_hr supp_freed resp_right res_hr_abuse rel_freedom pol_prison equ_opp forc_labour fr_dem_soc frd_inv_init free_speech freedom_act funda_freed honest_elect imp_trans hum_dig hum_prison hum_suffer human_right" 

local repression="withd_ch_opp rep_dem_opp int_opp crackd_opp pol_opp oppress gov_harass arrest aggress enddetpolopp initimidate persecute repress supp_freed"

local violence="viol_opp ren_viol gov_viol elect_viol prev_viol violence"

local num=_N

forvalues n=1/`num' 							{ 

	foreach l of varlist sanct-for_assist 		{

	local wc=wordcount(`l'[`n'])
		
		forvalues j = 1(1)`wc'					{

			di substr(word(`l'[`n'],`j'),1,strpos(word(`l'[`n'],`j'),":")-1)
			di real(substr(word(`l'[`n'],`j'),-(strlen(word(`l'[`n'],`j'))-strpos(word(`l'[`n'],`j'),":")),strlen(word(`l'[`n'],`j'))-strpos(word(`l'[`n'],`j'),":")))
			local i=substr(word(`l'[`n'],`j'),1,strpos(word(`l'[`n'],`j'),":")-1)
			local k=real(substr(word(`l'[`n'],`j'),-(strlen(word(`l'[`n'],`j'))-strpos(word(`l'[`n'],`j'),":")),strlen(word(`l'[`n'],`j'))-strpos(word(`l'[`n'],`j'),":")))

			foreach e in humrights violence repression {
				di "`e'"
				if ustrregexm("``e''","`i'")==1 {
					replace hrdoc=hrdoc+`k'	in `n'	
				}
						
			}
			
		}
		
}

}

}



quietly{

local humrights="min_wom adv_hr abuse dem_fre_act elim_slave elim_aparth univ_right un_dec_hr supp_freed resp_right res_hr_abuse rel_freedom pol_prison equ_opp forc_labour fr_dem_soc frd_inv_init free_speech freedom_act funda_freed honest_elect imp_trans hum_dig hum_prison hum_suffer human_right" 

local repression="withd_ch_opp rep_dem_opp int_opp crackd_opp pol_opp oppress gov_harass arrest aggress enddetpolopp initimidate persecute repress supp_freed"

local violence="viol_opp ren_viol gov_viol elect_viol prev_viol violence"

local coup="oust coup_risk coup dsrptlegpwr rest_consgvt" 

local democracy="dem_resist dem_process dem_outcome dem_goal dem_act comt_democz dem_elect dem_inst dem_path dem_prom dem_sol_act help_dem elect_gov democratic dem_value dem_solidar democracy democratizt grow_civ_soc pro_democ meet_int_std lack_legitld mlparty_dem toward_democ demelc_gov dem_govt dem_govnce dem_fre_act freedom_act dem_trans dem_evo fr_dem_soc rest_dem rest_demproc" 
	
local governance="demelc_gov dem_govt dem_govnce rule_law good_govnce const_neg exploit_rule" 

local transition="dem_trans dem_evo rest_dem rest_demproc trans supp_trans subtocivrule ref_med_polc normlz_gov enc_negot dem_change imp_trans open_pol_arn relinq_power sup_trans_gv rest_dem rest_demproc sup_ed_trans sup_ec_trans" 

local reform="sup_ed_trans sup_ec_trans und_ref_pro polec_reform pol_reform supp_reform" 

local election="frfa_pa_elec fraud elect_freed elect dem_fr_elect elect_fraud elect_res frfa_elec frfa_pp_elec rigg_elect prom_elect honest_elect frfa_ps_elec mlparty_elec ref_acce_res undem_elect unf_elect" 

local illiberal="exploit_rule postp_elect obstr_democ dict assault_dem mil polsocecodet unconaccessi und_dem_pro" 

local opposition="resp_opp opp_demand dem_opp withd_ch_opp rep_dem_opp int_opp disap_opp viol_opp" 

local arms="prhb_arm_tr mod_mil_rel" 

local assets="frz_fin_res asset_frz blck_prop_gv blck_gv blck_account blck_asset block_prop" 

local econaid="prhb_ecsupas prhb_hr_aid lim_fund withh_loan termn_assist rst_ness_ass cut_econ_bnf prhb_av_fund assist_cond reduc_assist no_ass_prov bar_fund bar_assist prhb_usefund block_fund gvgv_econmil furn_assist prhb_funds susp_assist cond_assist prhb_assist prhb_prv_ass limit_assist withh_assist prhb_rec_ass prhb_for_ass gov_assist rest_assist rev_assist cut_aid redu_aid restrict_aid susp_aid withh_aid withh_fund rest_for_ass rev_for_ass for_assist no_fundsexpn" 

local milaid="prhb_mil_ass susp_mil_trn rest_mil_ass prhb_fr_mil termn_milass termn_assist rst_ness_ass prhb_av_fund assist_cond reduc_assist no_ass_prov bar_fund bar_assist prhb_usefund block_fund gvgv_econmil furn_assist prhb_funds susp_assist cond_assist prhb_assist prhb_prv_ass limit_assist withh_assist prhb_rec_ass prhb_for_ass gov_assist rest_assist rev_assist cut_aid redu_aid restrict_aid susp_aid withh_aid withh_fund rest_for_ass rev_for_ass for_assist mod_mil_rel no_fundsexpn" 

local finance="trv_fin_sanc fin_trv_sanc cash_assist fin_sanc frz_fund block_loan prhb_transc prhb_payment unlic_fintra inv_sanc prhb_inv opp_loan lim_abl_fex prhb_finan" 
	
local smart="rest_int_trv susp_visa den_off_entr den_lics trv_sanct visa_ban susp_air_trn den_ent trv_ban deny_visa rest_trv trv_fin_sanc prhb_visa susp_entry prhb_entr fin_trv_sanc" 

local trade="exp_sanct rest_exp prhb_exp mod_econ_rel end_econ_ag end_trade_ag withh_trade prhb_imp rest_imp expimpbank trade_war ban_imp prhb_sale prhb_exim_bk boycott prhb_trade prhb_salesup sell_product cut_econ_bnf sanct_trade ecn_isol ecn_pol_isol" 

forvalues v=1/77 {

	local xy`v'=0

}


local num=_N

forvalues n=1/`num' 							{ 

	foreach l of varlist sanct-for_assist 		{

	local wc=wordcount(`l'[`n'])
		
		forvalues j = 1(1)`wc'					{

			local v=0

			di substr(word(`l'[`n'],`j'),1,strpos(word(`l'[`n'],`j'),":")-1)
			di real(substr(word(`l'[`n'],`j'),-(strlen(word(`l'[`n'],`j'))-strpos(word(`l'[`n'],`j'),":")),strlen(word(`l'[`n'],`j'))-strpos(word(`l'[`n'],`j'),":")))
			local i=substr(word(`l'[`n'],`j'),1,strpos(word(`l'[`n'],`j'),":")-1)
			local k=real(substr(word(`l'[`n'],`j'),-(strlen(word(`l'[`n'],`j'))-strpos(word(`l'[`n'],`j'),":")),strlen(word(`l'[`n'],`j'))-strpos(word(`l'[`n'],`j'),":")))

			* xv = 1-7 is x (mil aid, econ...) and y=humrights, 8-15 is x and y=vio ... xv71-77 x and y= opposition
			
			foreach e in humrights violence repression election democracy illiberal governance transition coup reform opposition {
				di "`e'"
				foreach f in milaid econaid trade finance assets smart arms {
					di "`f'"

					local v=`v'+1
					
					if ustrregexm("``e''","`i'")==1 & ustrregexm("``f''","`l'")==1 {

						local xy`v'=`xy`v''+`k'	
						replace heatmap=heatmap+1 in `n'

					}
				}		
			}
			
		}
		
}

}
noisily:di	"ycat","milaid","econaid","trade","finance","assets","smart","arms"
noisily:di	"election"	,	`xy1'	,	`xy2'	,	`xy3'	,	`xy4'	,	`xy5'	,	`xy6'	,	`xy7'
noisily:di	"democracy"	,	`xy8'	,	`xy9'	,	`xy10'	,	`xy11'	,	`xy12'	,	`xy13'	,	`xy14'
noisily:di	"illiberal"	,	`xy15'	,	`xy16'	,	`xy17'	,	`xy18'	,	`xy19'	,	`xy20'	,	`xy21'
noisily:di	"governance"	,	`xy22'	,	`xy23'	,	`xy24'	,	`xy25'	,	`xy26'	,	`xy27'	,	`xy28'
noisily:di	"transition"	,	`xy29'	,	`xy30'	,	`xy31'	,	`xy32'	,	`xy33'	,	`xy34'	,	`xy35'
noisily:di	"coup"	,	`xy36'	,	`xy37'	,	`xy38'	,	`xy39'	,	`xy40'	,	`xy41'	,	`xy42'
noisily:di	"reform"	,	`xy43'	,	`xy44'	,	`xy45'	,	`xy46'	,	`xy47'	,	`xy48'	,	`xy49'
noisily:di	"opposition"	,	`xy50'	,	`xy51'	,	`xy52'	,	`xy53'	,	`xy54'	,	`xy55'	,	`xy56'
noisily:di	"humrights"	,	`xy57'	,	`xy58'	,	`xy59'	,	`xy60'	,	`xy61'	,	`xy62'	,	`xy63'
noisily:di	"repression"	,	`xy64'	,	`xy65'	,	`xy66'	,	`xy67'	,	`xy68'	,	`xy69'	,	`xy70'
noisily:di	"violence"	,	`xy71'	,	`xy72'	,	`xy73'	,	`xy74'	,	`xy75'	,	`xy76'	,	`xy77'


}


